<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var partition = function (s) {
        const res = []
        function backTracking(path, start) {
          if (start == s.length) {
            return res.push([...path])
          }
          for (let i = start; i < s.length; i++) {
            let str = s.slice(start, i + 1)
            if (isPali(str)) {
              path.push(str)
              backTracking(path, i + 1)
              path.pop()
            }
          }
        }
        backTracking([], 0)
        return res

        function isPali(str) {
          let left = 0
          let right = str.length - 1
          while (left <= right) {
            if (str[left] != str[right]) {
              return false
            }
            left++
            right--
          }
          return true
        }
      }
    </script>
  </body>
</html>
